<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <!-- <label class="el-form-item-label"> 入库单 ID</label> -->
        <!-- <el-input v-model="query.inboundOrderId" clearable placeholder=" 入库单 ID" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" /> -->
        <label class="el-form-item-label">物料号</label>
        <el-input v-model="query.materialCode" clearable placeholder=" 物料号 " style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">批次号</label>
        <el-input v-model="query.batchNo" clearable placeholder=" 批次号 " style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">容器编码</label>
        <el-input v-model="query.containerCode" clearable placeholder=" 容器编码 " style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="120px">
          <el-form-item label="入库单ID">
            <el-input v-model="form.inboundOrderId" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="物料号">
            <el-input v-model="form.materialCode" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="批次号">
            <el-input v-model="form.batchNo" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="物料数量">
            <el-input v-model="form.materialQty" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="容器编码">
            <el-input v-model="form.containerCode" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="容器ID">
            <el-input v-model="form.containerId" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="库存ID">
            <el-input v-model="form.inventoryId" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="储位编码">
            <el-input v-model="form.storageCode" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="状态">
            <el-input v-model="form.status" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="第一次生产时间">
            <el-input v-model="form.firstProdTime" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="最后一根生产时间">
            <el-input v-model="form.lastProdTime" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="品质">
            <el-input v-model="form.quality" style="width: 250px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="inboundOrderId" label="入库单ID" />
        <el-table-column prop="materialCode" label="物料号" />
        <el-table-column prop="batchNo" label=" 批次号" />
        <el-table-column prop="materialQty" label="物料数量" />
        <el-table-column prop="containerCode" label="容器编码" />
        <el-table-column prop="containerId" label="容器ID" />
        <el-table-column prop="inventoryId" label="库存ID" />
        <el-table-column prop="storageCode" label="储位编码" />
        <el-table-column prop="status" label="状态" />
        <el-table-column prop="firstProdTime" label="第一次生产时间" />
        <el-table-column prop="lastProdTime" label="最后一根生产时间" />
        <el-table-column prop="quality" label="品质">
          <template slot-scope="scope">
            {{ dict.label.semi_material_status[scope.row.quality] }}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudSemiInboundOrderDetail from '@/api/jtWork/jtInboundOrderDetail'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = { id: null, inboundOrderId: null, materialCode: null, batchNo: null, materialQty: null, containerCode: null, containerId: null, inventoryId: null, storageCode: null, status: null, firstProdTime: null, lastProdTime: null, quality: null, createName: null, updateName: null, updateTime: null, createTime: null }
export default {
  name: 'JtInboundOrderDetail',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['semi_material_status'],
  cruds() {
    return CRUD({ title: 'semiInboundOrderDetail', url: 'semiApi/semiInboundOrderDetail', idField: 'id', sort: 'id,desc', crudMethod: { ...crudSemiInboundOrderDetail }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'semiInboundOrderDetail:add', 'otherUser'],
        edit: ['admin', 'semiInboundOrderDetail:edit', 'otherUser'],
        del: ['admin', 'semiInboundOrderDetail:del', 'otherUser']
      },
      rules: {
      },
      queryTypeOptions: [
        { key: 'inboundOrderId', display_name: '入库单ID' },
        { key: 'materialCode', display_name: '物料号' },
        { key: 'batchNo', display_name: '批次号' },
        { key: 'containerCode', display_name: '容器编码' }
      ]
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      this.query.inboundOrderId = this.$route.query.id
      return true
    }
  }
}
</script>

<style scoped>

</style>
